home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Utils / IceBreaker / Source / Console / IceBreaker.c next >
Encoding:
C/C++ Source or Header  |  1997-04-25  |  3.8 KB  |  136 lines

  1. /*
  2. ** ICE BREAKER (CONSOLE VERSION) V1.0
  3. ** ----------------------------------
  4. ** Author:    Paul Manias
  5. ** Date:      25 April 1997.
  6. ** Copyright: DreamWorld Productions 1997.
  7. ** Compile:   sc IceBreaker.c nolink
  8. **            PhxAss /IceAssembler.asm
  9. **            slink FROM lib:c.o,IceBreaker.o,/IceAssembler.o TO IceBreakerCon LIBRARY LIB:sc.lib,LIB:Amiga.lib
  10. **
  11. ** Doc:       This is the entry code for IceBreaker, it sets things up
  12. **            so that the assembler code is ready to intercept debug
  13. **            messages.  This particular version outputs to a console
  14. **            window - preferably KCON: but CON: is accepted as well.
  15. **
  16. */
  17.  
  18. #include <proto/games.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <dos/dos.h>
  22.  
  23. extern struct ExecBase *SysBase;
  24. extern struct GFXBase *GFXBase;
  25.  
  26. #define LVODEBUGMESSAGE -378
  27. #define LVOERRORMESSAGE -384
  28. #define LVOSTEPBACK     -390
  29.  
  30. extern ULONG (libDebugMessage)();
  31. extern ULONG (libErrorMessage)();
  32. extern ULONG (libStepBack)();
  33.  
  34. struct GMSBase *GMSBase;
  35. struct Task *maintask;
  36. struct Task *edittask = NULL;
  37.  
  38. BPTR conhandle=0;      /* Handle to output debug information */
  39.  
  40. /***************************** INITIALISATION CODE *********************************/
  41.  
  42. void mainroutine(void);
  43. long getlen(char string[]);
  44. void wtext(char string[]);
  45. BPTR openconsole(void);
  46.  
  47. void main(void)
  48. {
  49.  void *oldDebugMessage;
  50.  void *oldErrorMessage;
  51.  void *oldStepBack;
  52.  
  53.  maintask = FindTask(0);
  54.  
  55.  if (GMSBase = (struct GMSBase *) OpenLibrary("GMS:GPI/Master.GPI",0)) {
  56.   if (DebugActive() == ERR_OK) {
  57.    if (GFXBase = (struct GFXBase *) OpenLibrary("graphics.library",0)) {
  58.     if (conhandle = openconsole()) {
  59.  
  60.        Forbid();
  61.        oldDebugMessage = SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,&libDebugMessage);
  62.        oldErrorMessage = SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,&libErrorMessage);
  63.        oldStepBack     = SetFunction((struct Library *)GMSBase,LVOSTEPBACK,&libStepBack);
  64.        SumLibrary((struct Library *)GMSBase);
  65.        Permit();
  66.  
  67.        mainroutine();
  68.  
  69.        Forbid();
  70.        SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,oldDebugMessage);
  71.        SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,oldErrorMessage);
  72.        SetFunction((struct Library *)GMSBase,LVOSTEPBACK,oldStepBack);
  73.        SumLibrary((struct Library *)GMSBase);
  74.        Permit();
  75.  
  76.     Close(conhandle);
  77.     }
  78.    CloseLibrary((struct Library *)GFXBase);
  79.    }
  80.   DebugInactive();
  81.   }
  82.  CloseLibrary((struct Library *)GMSBase);
  83.  }
  84. }
  85.  
  86. /*********************************** MAIN LOOP *************************************/
  87.  
  88. void mainroutine(void)
  89. {
  90.   LONG result;
  91.  
  92.   wtext("Welcome to IceBreaker V1.0, the debugger for GMS programs.\n");
  93.   wtext("This program will wait until a program using GMS is executed.  Any\n");
  94.   wtext("debug messages that are sent while it is active will be intercepted\n");
  95.   wtext("and printed out to this window.\n\n");
  96.   wtext("Press CTRL-C at any time to exit.\n\n");
  97.   wtext("Type                 | Data\n");
  98.   wtext("---------------------+---------------------------------------------\n");
  99.  
  100.   do {
  101.      result = Wait(SIGBREAKF_CTRL_C);
  102.   } while (!(result & SIGBREAKF_CTRL_C));
  103.  
  104. }
  105.  
  106. /***********************************************************************************/
  107.  
  108. void wtext(char string[]) {
  109.   Write(conhandle,string,getlen(string));
  110. }
  111.  
  112. /***********************************************************************************/
  113.  
  114. long getlen(char string[]) {
  115.   int length=0;
  116.  
  117.   while (string[length] != 0) {
  118.     length++;
  119.     if (length > 256) break;
  120.   }
  121.   return(length);
  122. }
  123.  
  124. /***********************************************************************************/
  125.  
  126. BPTR openconsole(void) {
  127.   BPTR handle;
  128.  
  129.   if (handle = Open("KCON:0/20/640/200/Function Output/SCREEN IceBreaker",MODE_OLDFILE)) {
  130.      return(handle);
  131.   }
  132.   else
  133.      return(Open("CON:0/20/640/200/Function Output/SCREEN IceBreaker",MODE_OLDFILE));
  134. }
  135.  
  136.